home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / gui / gui4cli.lha / Gui4Cli / Ext / Exmpl_src / LV_Routines.h < prev   
C/C++ Source or Header  |  1998-10-22  |  4KB  |  148 lines

  1.  
  2. // ================================================================
  3. // Delete all selected or unselected records - return success
  4. // - fls - the fulist structure 
  5. // - state - 0 = delete unselected, 1 = delete selected
  6. // ================================================================
  7. delselrec (struct fulist *fls, BOOL state)
  8. {
  9. LONG del = 0;
  10. struct lister *fl, *nextfl;
  11.  
  12. if (!fls || (!(fls->magic == MM_LISTVIEW))) return (0);
  13.  
  14. fl = (struct lister *)fls->ls->lh_Head;
  15. while (nextfl = (struct lister *)(fl->node.ln_Succ))
  16. {
  17.     if (fl->Selected == state)
  18.     {
  19.         // if it's the current record, null pointer
  20.         if (fl == fls->curpt)
  21.         {   fls->curpt = NULL;
  22.             fls->line  = -1;
  23.         }
  24.         // remove node from list and free memory
  25.         Remove  (&fl->node);
  26.         FreeMem (fl->start, (fl->length+1));
  27.         FreeMem (fl, sizeof(struct lister));
  28.         ++del;
  29.     }
  30.     fl = nextfl;
  31. }
  32. // if the current record still exists, adjust it's line number
  33. if (fls->curpt)
  34.     fls->line = findrecnum (fls, rec);
  35.  
  36. return (1);
  37. }
  38.  
  39. // ================================================================
  40. // Delete a listview record - return success
  41. // - will adjust the CURRENT Record pointer, remove the record
  42. //   from the list and free the relevant memory.
  43. // ================================================================
  44. delrec (struct lister *rec)
  45. {
  46. struct fulist *fls;
  47. struct lister *r;
  48. LONG c;
  49.  
  50. if (!rec || (!(fls = rec->fls))) return (0);
  51.  
  52. // adjust pointers if this is the "current" record
  53. if (rec == fls->curpt)
  54. {  // if it's the 1st record, make next one current
  55.    if (fls->curpt == (struct lister *)fls->ls->lh_Head)
  56.        fls->curpt = (struct lister *)fls->curpt->node.ln_Succ;
  57.    // otherwise, make previous one current
  58.    else
  59.    {   fls->curpt = (struct lister *)fls->curpt->node.ln_Pred;
  60.        --fls->line;  // decrease current line number
  61.    }
  62.    // check if current record is still valid and null if not
  63.    if (!fls->curpt || (fls->curpt == (struct lister *)fls->ls->lh_Tail))
  64.    {   fls->curpt = NULL; 
  65.        fls->line  = -1;  
  66.    }
  67. }
  68. // otherwise adjust the current line number
  69. else
  70. {  // find the record number
  71.    if ((c = findrecnum(fls, rec)) < 0) return (0);
  72.    // if rec is before the current record...
  73.    if (c < fls->line) --fls->line;
  74. }
  75.  
  76. // remove node from list and free memory
  77. Remove  (&rec->node);
  78. FreeMem (rec->start, (rec->length+1));
  79. FreeMem (rec, sizeof(struct lister));
  80.  
  81. // decrease the total record counter
  82. --(fls->totnum);
  83. }
  84.  
  85. // ================================================================
  86. // Find a record - return it's line number or -1 if not found
  87. // - rec = a pointer to the record
  88. // - fls = a pointer to the parent fulist struct
  89. // ================================================================
  90. findrecnum (struct fulist *fls, struct lister *rec)
  91. {
  92. LONG c = 0;
  93. struct lister *fl, *nextfl;
  94.  
  95. fl = (struct lister *)fls->ls->lh_Head;
  96. while (nextfl = (struct lister *)(fl->node.ln_Succ))
  97. {   if (fl == rec) return (c);
  98.     fl = nextfl;
  99.     ++c;
  100. }
  101. PutStr ("ERROR: Could not find record\n");
  102. return (-1);
  103. }
  104.  
  105. // ================================================================
  106. // Find a record by number - return record pointer or NULL
  107. // - fls = the parent fulist structure
  108. // - num = the number of the record we're looking for
  109. // ================================================================
  110. struct lister *findrec (struct fulist *fls, LONG num)
  111. {
  112. struct lister *fl, *nextfl;
  113. register LONG c = 0;
  114.  
  115. if (!fls) return (NULL);
  116. if ((num >= fls->totnum) || (num < 0))
  117. {  PutStr ("ERROR: Record out of range\n");
  118.    return (NULL);
  119. }
  120. // loop to find the record..
  121. fl = (struct lister *)(fls->ls->lh_Head);
  122. while (nextfl = (struct lister *)(fl->node.ln_Succ))
  123. {  if (c == num) return (fl);
  124.    fl = nextfl;
  125.    ++c;
  126. }
  127. return (NULL);
  128. }
  129.  
  130.  
  131. // ==============================================================
  132. //    - Allocate & initialise a new List structure
  133. // ==============================================================
  134. // prototype needed
  135. void NewList (struct List *list);
  136.  
  137. struct List *getlist (void)
  138. {
  139. struct List *ls;
  140.  
  141. if (!(ls = (struct List *)AllocMem(sizeof(struct List), MEMF_CLEAR))) 
  142.     return (NULL);
  143. NewList (ls);
  144. return (ls);
  145. }
  146.  
  147.  
  148.